<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是Linux——软件包管理相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV02-01-Linux-01-软件包管理">
<meta property="og:url" content="https://sumumm.github.io/post/dcb00192.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是Linux——软件包管理相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV02-%E7%BC%96%E8%AF%91%E5%9F%BA%E7%A1%80/LV02-01-Linux-01-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86/img/image-20220124184915131.png">
<meta property="article:published_time" content="2022-02-20T07:00:19.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:56.987Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV02-编译基础">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV02-%E7%BC%96%E8%AF%91%E5%9F%BA%E7%A1%80/LV02-01-Linux-01-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86/img/image-20220124184915131.png">


<link rel="canonical" href="https://sumumm.github.io/post/dcb00192.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/dcb00192.html","path":"post/dcb00192.html","title":"LV02-01-Linux-01-软件包管理"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV02-01-Linux-01-软件包管理 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-%E6%B5%81%E8%A1%8C%E7%9A%84%E4%B8%A4%E7%A7%8D%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86%E6%9C%BA%E5%88%B6"><span class="nav-text">1.流行的两种软件包管理机制</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%9A%84%E7%B1%BB%E5%9E%8B"><span class="nav-text">2.软件包的类型</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%9A%84%E5%91%BD%E5%90%8D"><span class="nav-text">3.软件包的命名</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7%E5%88%86%E7%B1%BB"><span class="nav-text">4.软件包管理工具分类</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-dpkg-%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4"><span class="nav-text">5. dpkg 相关命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-APT%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7"><span class="nav-text">6.APT管理工具</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#6-1-apt%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="nav-text">6.1 apt是什么？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-apt-%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86"><span class="nav-text">6.2 apt 工作原理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-3-apt%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4"><span class="nav-text">6.3 apt相关命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-1%E5%91%BD%E4%BB%A4%E6%A0%BC%E5%BC%8F"><span class="nav-text">6.3.1命令格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-2%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="nav-text">6.3.2常用命令</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/dcb00192.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV02-01-Linux-01-软件包管理 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV02-01-Linux-01-软件包管理
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-02-20 15:00:19" itemprop="dateCreated datePublished" datetime="2022-02-20T15:00:19+08:00">2022-02-20</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV02-%E7%BC%96%E8%AF%91%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">LV02-编译基础</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.6k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>13 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是Linux——软件包管理相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV02-%E7%BC%96%E8%AF%91%E5%9F%BA%E7%A1%80/LV02-01-Linux-01-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">---</td><td align="left"><a href="" target="_blank">--- <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<h1 id="1-流行的两种软件包管理机制"><a href="#1-流行的两种软件包管理机制" class="headerlink" title="1.流行的两种软件包管理机制"></a><font size=3>1.流行的两种软件包管理机制</font></h1><p>Debian  Linux 首先提出“软件包”的管理机制—— Deb 软件包 。就是将应用程序的二进制文件、配置文档、 man&#x2F;info 帮助页面等文件合并打包在一个文件中，用户使用软件包管理器直接操作软件包，完成获取、安装、卸载、查询等操作。</p>
<p> Redhat Linux 基于这个理念推出了自己的软件包管理机制—— Rpm 软件包 。</p>
<p>随着 Linux 操作系统规模的不断扩大，系统中软件包间复杂的依赖关系，导致 Linux 用户麻烦不断。所以 Debian Linux 开发出了 APT软件包管理器 。它可以<strong>检查和修复软件包依赖关系</strong>，利用 Internet 网络帮助用户<strong>主动获取软件包</strong>。 APT 工具再次促进了 Deb 软件包更为广泛地使用，成为 Debian Linux 的一个无法替代的亮点。</p>
<h1 id="2-软件包的类型"><a href="#2-软件包的类型" class="headerlink" title="2.软件包的类型"></a><font size=3>2.软件包的类型</font></h1><p>大概有两种类型，如下表所示：</p>
<table>
<thead>
<tr>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>二进制软件包（ Binary Packages ）</td>
<td>它包含可执行文件、库文件、配置文件、 man&#x2F;info 页面、版权声明和其它文档。</td>
</tr>
<tr>
<td>源码包（ Source Packages ）</td>
<td>包含软件源代码、版本修改说明、构建指令以及编译工具等。先由tar工具归档为 .tar.gz 文件，然后再打包成 .dsc 文件。</td>
</tr>
</tbody></table>
<h1 id="3-软件包的命名"><a href="#3-软件包的命名" class="headerlink" title="3.软件包的命名"></a><font size=3>3.软件包的命名</font></h1><p>一般命名格式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Filename_Version-Reversion_Architecture.deb</span><br></pre></td></tr></table></figure>

<p><strong>【参数说明】</strong></p>
<table>
    <tr>
        <td align="center">Filename</td>
        <td align="center">软件包名称</td>
    </tr>
    <tr>
        <td align="center">Version</td>
        <td align="center">软件版本</td>
    </tr>
    <tr>
        <td align="center">Reversion</td>
        <td align="center">修订版本</td>
    </tr>
    <tr>
        <td align="center">Architecture</td>
        <td align="center">体系架构</td>
    </tr>
</table>

<p>例如：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV02-%E7%BC%96%E8%AF%91%E5%9F%BA%E7%A1%80/LV02-01-Linux-01-%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86/img/image-20220124184915131.png" alt="image-20220124184915131" style="zoom: 80%;" />

<h1 id="4-软件包管理工具分类"><a href="#4-软件包管理工具分类" class="headerlink" title="4.软件包管理工具分类"></a><font size=3>4.软件包管理工具分类</font></h1><p>常见的软件包管理工具有以下三类：</p>
<table>
    <tr>
        <td align="center" width=100px>类别</td>
        <td align="center" width=120px>软件包名称</td>
        <td align="center">描述</td>
    </tr>
    <tr>
        <td align="center">命令行</td>
        <td align="center">dpkg-deb<br>dpkg<br>apt
</td>
        <td align="left">在命令行模式下完成软件包管理任务。为完成软件包的获取、查询、软件包依赖性检查、安装、卸载等任务，需要使用各自不同的命令
</td>
    </tr>
    <tr>
        <td align="center">文本窗口界面</td>
        <td align="center">dselect<br>aptitude<br>tasksel
</td>
        <td align="left">在文本窗口模式中，使用窗口和菜单可以完成软件包管理任务
</td>
    </tr>
    <tr>
        <td align="center">图形界面</td>
        <td align="center">synaptic
</td>
        <td align="left">在X-Window图形桌面环境中运行，具有更好的交互性、可读性、易用性等特点
</td>
    </tr>
</table>

<h1 id="5-dpkg-相关命令"><a href="#5-dpkg-相关命令" class="headerlink" title="5. dpkg 相关命令"></a><font size=3>5. dpkg 相关命令</font></h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">dpkg -i &lt;.deb file_name&gt; # 安装一个在本地文件系统上存在的Debian软件包</span><br><span class="line">dpkg -L &lt;package&gt;  # 列出与该包相关联的文件，也可以查看安装包的安装位置 </span><br><span class="line">dpkg -r &lt;package&gt;  # 移除已经安装的软件包，但是保留配置文件</span><br><span class="line">dpkg -P &lt;package&gt;  # 移除已安装的软件包，同时移除配置文件</span><br><span class="line">dpkg -s &lt;package&gt;  # 显出软件包的安装状态,包含包的详细信息</span><br><span class="line">dpkg -c &lt;package&gt;  # 查看软件包的内容</span><br><span class="line">dpkg -l            # 列出当前系统中已经安装的软件以及软件包的状态</span><br></pre></td></tr></table></figure>

<h1 id="6-APT管理工具"><a href="#6-APT管理工具" class="headerlink" title="6.APT管理工具"></a><font size=3>6.APT管理工具</font></h1><h2 id="6-1-apt是什么？"><a href="#6-1-apt是什么？" class="headerlink" title="6.1 apt是什么？"></a><font size=3>6.1 apt是什么？</font></h2><p>Advanced Packaging Tool（apt）是Linux下的一款安装包管理工具，是一个客户&#x2F;服务器系统。常用于在Ubuntu、Debian和相关Linux发行版上安装、更新、删除和管理deb软件包。</p>
<h2 id="6-2-apt-工作原理"><a href="#6-2-apt-工作原理" class="headerlink" title="6.2 apt 工作原理"></a><font size=3>6.2 apt 工作原理</font></h2><p>在 Ubuntu 系统中，使用软件源配置文件 &#x2F;etc&#x2F;apt&#x2F;sources.list  列出最合适访问的镜像站点地址。软件源配置文件只是告知 Ubuntu 系统可以访问的镜像站点地址。但那些镜像站点都拥有什么软件资源并不清楚。若是每安装一个软件包，就在服务器上寻找一边，效率是很低的。因而，就有必要为这些软件资源列个清单（建立索引文件），以便本地主机查询。</p>
<ul>
<li>软件源</li>
</ul>
<p>根据软件包的开发组织对该软件的支持程度，以及遵从的开源程度，划分为四类：</p>
<table>
    <tr>
        <td align="center" width=200px>核心（Main）</td>
        <td align="left">官方维护的开源软件，是由Ubuntu官方完全支持的软件，包括大多数流行的、稳定的开源软件，是Ubuntu默认安装的基本软件包</td>
    </tr>
    <tr>
        <td align="center" width=200px>公共（Universe）</td>
        <td align="left">社区维护的开源软件，是由Ubuntu社区的计算机爱好者维护的软件。这些软件包没有安全升级的保障。用户在使用时，需要考虑这些软件包存在的不稳定性</td>
    </tr>
    <tr>
        <td align="center" width=200px>受限（Restricted）</td>
        <td align="left">官方维护的非开源软件，是专供特殊用途，而且没有自由软件版权，不能直接修改软件，但依然被Ubuntu团队支持的软件</td>
    </tr>
    <tr>
        <td align="center" width=200px>多元化（Multiverse）</td>
        <td align="left">非Ubuntu官方维护的非开源软件，用户使用这些软件包时，需要特别注意版权问题</td>
    </tr>
</table>

<ul>
<li>软件源配置文件 &#x2F;etc&#x2F;apt&#x2F;sources.list</li>
</ul>
<p> &#x2F;etc&#x2F;apt&#x2F;sources.list 本质就是一个普通的文本文件，可以在超级管理员授权下，使用任何文本编辑器进行编辑。在该文件中，添加的软件源镜像站点称为一个配置项，并遵循以下格式：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">DebType  AddressType://Hostaddress/Ubuntu  Distribution  Component1  Component2……</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">例如</span></span><br><span class="line">deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted</span><br></pre></td></tr></table></figure>

<ul>
<li>软件包存储位置 &#x2F;var&#x2F;cache&#x2F;apt&#x2F;archives</li>
</ul>
<p> &#x2F;var&#x2F;cache&#x2F;apt&#x2F;archives 中主要 apt-get 命令下载的 deb 软件包；另有一个文件 lock ，随 apt-get 启动而建立，随 apt-get 退出而删除，用以保证同一时间只有一个 apt-get 进程；还有一个文件夹 partial ，用以存放正在下载的软件包（下载完成后会被移动到上一级文件夹）。</p>
<ul>
<li>刷新软件源</li>
</ul>
<p>修改了配置文件—— &#x2F;etc&#x2F;apt&#x2F;sources.list ，只是告知软件源镜像站点的地址。但那些所指向的镜像站点所具有的软件资源并不清楚，需要将这些资源列个清单，以便本地主机知晓可以申请哪些资源。此时使用使用 apt-get update 命令扫描每一个软件源服务器，并为该服务器所具有软件包资源建立索引文件，存放在本地的 &#x2F;var&#x2F;lib&#x2F;apt&#x2F;lists&#x2F; 目录中。</p>
<h2 id="6-3-apt相关命令"><a href="#6-3-apt相关命令" class="headerlink" title="6.3 apt相关命令"></a><font size=3>6.3 apt相关命令</font></h2><h3 id="6-3-1命令格式"><a href="#6-3-1命令格式" class="headerlink" title="6.3.1命令格式"></a><font size=3>6.3.1命令格式</font></h3><p>在 Ubuntu Linux 中，通常使用 apt-get 命令管理软件包，只需告知软件包名字，就可以自动完成软件包的获取、安装、编译和卸载，以及检查软件包依赖关系。 也经常通过 apt-cache 来查询软件包相关信息。要注意的是大多数的情况需要给管理员权限即要加上 sudo 。</p>
<div class="tabs" id="apt"><ul class="nav-tabs"><li class="tab active"><a href="#apt-1">apt-get</a></li><li class="tab"><a href="#apt-2">apt-cache</a></li></ul><div class="tab-content"><div class="tab-pane active" id="apt-1"><ul>
<li><strong>apt-get</strong></li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get subcommands [option] pkg</span><br></pre></td></tr></table></figure>


<details class="folding-tag" blue><summary> 点击查看 参数说明 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" rowspan="12" width=100px>subcommands</td>        <td align="center" width=150px>update</td>        <td align="left">下载更新软件包列表信息</td>    </tr>    <tr>        <td align="center" width=150px>upgrade</td>        <td align="left">将系统中所有软件包升级到最新的版本</td>    </tr>    <tr>        <td align="center" width=150px>install</td>        <td align="left">下载所需软件包并进行安装配置</td>    </tr>    <tr>        <td align="center" width=150px>remove</td>        <td align="left">卸载软件包</td>    </tr>    <tr>        <td align="center" width=150px>autoremove</td>        <td align="left">将不满足依赖关系的软件包自动卸载</td>    </tr>    <tr>        <td align="center" width=150px>source</td>        <td align="left">下载源码包</td>    </tr>    <tr>        <td align="center" width=150px>build-dep</td>        <td align="left">为源码包构建所需的编译环境</td>    </tr>    <tr>        <td align="center" width=150px>dist-upgrade</td>        <td align="left">发布版升级</td>    </tr>    <tr>        <td align="center" width=150px>dselect-upgrade </td>        <td align="left">根据dselect的选择来进行软件包升级</td>    </tr>    <tr>        <td align="center" width=150px>clean</td>        <td align="left">删除缓存区中所有已下载的包文件</td>    </tr>    <tr>        <td align="center" width=150px>autoclean</td>        <td align="left">删除缓存区中老版本的己下载的包文件</td>    </tr>    <tr>        <td align="center" width=150px>check</td>        <td align="left">检查系统中依赖关系的完整性</td>    </tr>    <tr>        <td align="center" rowspan="12" width=100px>option</td>        <td align="center" width=150px>-d</td>        <td align="left">仅下载软件包，而不安装或解压</td>    </tr>    <tr>        <td align="center" width=150px>-f</td>        <td align="left">修复系统中存在的软件包依赖性问题</td>    </tr>    <tr>        <td align="center" width=150px>-m</td>        <td align="left">当发现缺少关联软件包时，仍试图继续执行</td>    </tr>    <tr>        <td align="center" width=150px>-q</td>        <td align="left">将输出作为日志保留，不获取命令执行进度</td>    </tr>    <tr>        <td align="center" width=150px>--purge</td>        <td align="left">与remove子命令一起使用，完全卸载软件包</td>    </tr>    <tr>        <td align="center" width=150px>-reinstall</td>        <td align="left">与install子命令一起使用，重新安装软件包</td>    </tr>    <tr>        <td align="center" width=150px>-b</td>        <td align="left">在下载完源码包后，编译生成相应的软件包</td>    </tr>    <tr>        <td align="center" width=150px>-s</td>        <td align="left">不做实际操作，只是模拟命令执行结果</td>    </tr>    <tr>        <td align="center" width=150px>-y</td>        <td align="left">对所有询问都作肯定的回答，apt-get不再进行任何提示</td>    </tr>    <tr>        <td align="center" width=150px>-u</td>        <td align="left">获取已升级的软件包列表</td>    </tr>    <tr>        <td align="center" width=150px>-h</td>        <td align="left">获取帮助信息</td>    </tr>    <tr>        <td align="center" width=150px>-v</td>        <td align="left">获取apt-get版本号</td>    </tr></table>
              </div>
            </details></div><div class="tab-pane" id="apt-2"><ul>
<li><strong>apt-cache</strong></li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-cache subcommands [option] pkg</span><br></pre></td></tr></table></figure>


<details class="folding-tag" blue><summary> 点击查看 参数说明 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" rowspan="9" width=100px>subcommands</td>        <td align="center" width=150px>showpkg</td>        <td align="left">获取二进制软件包的常规描述信息</td>    </tr>    <tr>        <td align="center" width=150px>showsrc</td>        <td align="left">获取源码包的详细描述信息</td>    </tr>    <tr>        <td align="center" width=150px>show</td>        <td align="left">获取二进制软件包的详细描述信息</td>    </tr>    <tr>        <td align="center" width=150px>stats</td>        <td align="left">获取软件源的基本统计信息</td>    </tr>    <tr>        <td align="center" width=150px>search</td>        <td align="left">根据正则表达式检索软件包</td>    </tr>    <tr>        <td align="center" width=150px>depends</td>        <td align="left">获取该软件包的依赖信息</td>    </tr>    <tr>        <td align="center" width=150px>rdepends</td>        <td align="left">获取所有依赖于该软件包的软件包</td>    </tr>    <tr>        <td align="center" width=150px>pkgnames</td>        <td align="left">列出所有已安装软件包的名字</td>    </tr>    <tr>        <td align="center" width=150px>policy</td>        <td align="left">获取软件包当前的安装状态</td>    </tr>    <tr>        <td align="center" width=100px>option</td>        <td align="left" width=150px colspan="2">有[ -p | -s | - q | - i | - c | -h  ]等, 但是不怎么用，详情可查看手册(man apt-cache)</td>    </tr></table>
              </div>
            </details></div></div></div>


<h3 id="6-3-2常用命令"><a href="#6-3-2常用命令" class="headerlink" title="6.3.2常用命令"></a><font size=3>6.3.2常用命令</font></h3><p>在使用以下命令时，若提示没有权限，则可以在前边加上 sudo 。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">1.修复软件包依赖关系</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">如果由于故障而中断软件安装过程，可能会造成关联的软件包只有部分安装。之后，可能就会发现该软件既不能重装又不能删除，就可以使用以下两条命令。</span></span><br><span class="line">apt-get check      # 检查软件包依赖关系</span><br><span class="line">apt-get -f install # 修复依赖关系</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">2.更新软件包</span></span><br><span class="line">apt-get upgrade    # 将系统中的所有软件包一次性升级到最新版本。</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">3.安装软件包</span> </span><br><span class="line">apt-get install &lt;package_name&gt;  </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">当用户不小心损坏了已安装的软件包，而需要修复。或者，希望重新安装软件包中某些文件的最新版本，可以重新安装软件包。</span>  </span><br><span class="line">apt-get  --reinstall  install &lt;soft_name&gt;</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">4.卸载软件包</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除一个软件包时，将会连带删除与该软件包有依赖关系的软件包。</span> </span><br><span class="line">apt-get remove &lt;package_name&gt;         # 不完全卸载</span><br><span class="line">apt-get --purge remove &lt;package_name&gt; # 包括配置文件</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">5.清理软件包缓冲区</span></span><br><span class="line">apt-get clean     # 删除全部下载的软件包</span><br><span class="line">apt-get autoclean # 如果希望缓冲区中只保留最新版本的软件包，多余版本全部清除，可使用该命令</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">6.查询软件包信息</span></span><br><span class="line">apt-cache show</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">7.获取软件包安装状态</span> </span><br><span class="line">apt-cache policy</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/dcb00192.html">LV02-01-Linux-01-软件包管理</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2022年02月20日 - 15:00</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/dcb00192.html" title="LV02-01-Linux-01-软件包管理">https://sumumm.github.io/post/dcb00192.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV02-%E7%BC%96%E8%AF%91%E5%9F%BA%E7%A1%80/" rel="tag"><i class="fa fa-tag"></i> LV02-编译基础</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/1d45066.html" rel="prev" title="LV02-01-Linux-02-文件系统">
                  <i class="fa fa-angle-left"></i> LV02-01-Linux-02-文件系统
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/e57fdc7f.html" rel="next" title="LV01-08-C语言-多文件">
                  LV01-08-C语言-多文件 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
